﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;

public partial class Views_module_userhistory : System.Web.UI.UserControl
{
    private CustomerBus cusBus;
    private OrderBus orBus;
    protected void Page_Load(object sender, EventArgs e)
    {
        cusBus = new CustomerBus();
        orBus = new OrderBus();
        Data();
    }
    public void Data()
    {
        DataTable datacurren = DataDefault();
        order or = new order();
        Customer cus = new Customer();
        string email = Convert.ToString(Session["username"]);
        cus = cusBus.getCustomerByEmail(email);
        DataTable dt = new DataTable();
        dt = orBus.getOrderByCustomerID(cus.Customer_id);
        DataRow dr;
        foreach (DataRow r in dt.Rows)
        {
            DataTable totalProduct=new DataTable();
            totalProduct=orBus.getOrderProductByOrder_id(Convert.ToInt32(r["order_id"]));

            dr = datacurren.NewRow();
            dr["date_added"] = r["date_added"].ToString();
            dr["total_order_product_id"] = totalProduct.Rows.Count;
            dr["total"] = r["total"];
            dr["order_id"] = r["order_id"];
            datacurren.Rows.Add(dr);
        }
        
        history.DataSource = datacurren;
        history.DataBind();

    }
    public DataTable DataDefault()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("date_added");
        dt.Columns.Add("total_order_product_id");
        dt.Columns.Add("total");
        dt.Columns.Add("order_id");
        return dt;
    }
}